//
//  FunScendViewController.m
//  MarryMe
//
//  Created by lanou3g on 16/1/7.
//  Copyright © 2016年 revocher. All rights reserved.
//

#import "FunScendViewController.h"
#import "FunScendTableViewCell.h"
#import "FunModel.h"
#import "DataTool.h"
@interface FunScendViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)NSArray *array;
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation FunScendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.title=@"结婚助手";
    [self.tableView registerNib:[UINib nibWithNibName:@"FunScendTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FunScendTableViewCell"];
    UIBarButtonItem *buttonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonItem:)];
    self.navigationItem.leftBarButtonItem=buttonItem;
  
    if (self.city==nil) {
     self.city=@"1";
    }
      [self getDate];
}




-(void)buttonItem:(UIBarButtonItem*)sender{
    [self.navigationController popToRootViewControllerAnimated:YES];
}


-(void)getDate{
    [DataTool requeueWithurlString:[NSString stringWithFormat:@"http://www.hunliji.com/v1/api/app/wedding_registers.json?city_id=%@&page=1&per_page=99",self.city] withHTTPMethod:nil withHttPBody:nil backBlock:^(id object) {
        NSArray *arr=(NSArray*)object;
        self.array=[NSArray array];
        NSMutableArray *data=[NSMutableArray array];
        for (NSDictionary *dic in arr) {
            FunModel *model=[[FunModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [data addObject:model];
        }
        self.array =[NSArray arrayWithArray:data];
        NSLog(@"%@",self.array);
        [self.tableView reloadData];

    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FunScendTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"FunScendTableViewCell"];
    FunModel *model=[[FunModel alloc]init];
    model= self.array[indexPath.row];
    [cell setCellFunModel:model];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 195;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
